import 'package:flutter/material.dart';
import '../../models/adress_info_model.dart';
import '../../l10n/app_localizations.dart';

class AdressCell extends StatelessWidget {
  final AdressInfo model;
  final VoidCallback? onDelete;
  final VoidCallback? onSet;

  const AdressCell({
    super.key,
    required this.model,
    this.onDelete,
    this.onSet,
  });

  @override
  Widget build(BuildContext context) {
    final bool showDefault = model.defaultAddress == "1";
    return Padding(
      padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 5),
      child: Container(
        height: 150,
        padding: const EdgeInsets.all(13),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(12),
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            // 第一行：姓名 + 手机
            Row(
              children: [
                Expanded(
                  child: SizedBox(
                    width: MediaQuery.of(context).size.width / 2,
                    child: Text(
                      '${model.firstName}${model.lastName}',
                      style: const TextStyle(fontSize: 16, color: Color(0xFF333333)),
                      overflow: TextOverflow.ellipsis,
                      maxLines: 1,
                    ),
                  ),
                ),
                Text(
                  '+${model.phoneCode} ${model.phoneNumber}',
                  style: const TextStyle(fontSize: 16, color: Color(0xFF666666)), // label666Color
                  textAlign: TextAlign.right,
                ),
              ],
            ),
            const SizedBox(height: 15),
            // 第二行：地址行1（含类型图标）
            Row(
              children: [
                Expanded(
                  child: Text(
                    model.email,
                    style: const TextStyle(fontSize: 16, color: Color(0xFF333333)),
                  ),
                ),
                Image.asset(
                  model.type == 0 ? 'assets/images/adresstype0.png' : 'assets/images/adresstype1.png',
                  width: 25,
                  height: 19,
                )
              ],
            ),
            const SizedBox(height: 10),
            // 分割线
            const Divider(height: 24, thickness: 1, color: Color(0xFFF5F5F5)), // bgColor
            // 最后一行：默认标识 + 按钮
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                // 左侧：默认标识（没有就占位）
                showDefault
                    ? Container(
                        padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
                        decoration: BoxDecoration(
                          color: const Color(0xFFF3F3FF),
                          borderRadius: BorderRadius.circular(5),
                        ),
                        child: Text(
                          AppLocalizations.of(context)!.defaultsa,
                          style: const TextStyle(fontSize: 16, color: Color(0xFF2A67F9)),
                          textAlign: TextAlign.center,
                        ),
                      )
                    : const SizedBox(width: 40), // 占位保持结构

                // 右侧：删除和设置按钮
                Row(
                  children: [
                    GestureDetector(
                      onTap: onDelete,
                      child: Image.asset(
                        'assets/images/deletebtn.png',
                        width: 20,
                        height: 20,
                      ),
                    ),
                    const SizedBox(width: 15),
                    GestureDetector(
                      onTap: onSet,
                      child: Image.asset(
                        'assets/images/setbtn.png',
                        width: 20,
                        height: 20,
                      ),
                    ),
                  ],
                )
              ],
            )

          ],
        ),
      ),
    );
  }
}
